using System.Diagnostics;

namespace TouchSmart.Animations
{
    public class LinearAnimation : TwoDimensionsAnimation
    {
        public LinearAnimation(float xVelocity, float yVelocity) 
            : base(xVelocity, yVelocity) { }

        protected override float GetXMovement(int delta)
        {
            return this._xVelocity * delta;
        }

        protected override float GetYMovement(int delta)
        {
            return this._yVelocity * delta;
        }
    }

    public class DecelerationAnimation : TwoDimensionsAnimation
    {
        private float _deceleration = -0.4f;
        private float _startXVelocity;
        private float _startYVelocity;

        public DecelerationAnimation(float xVelocity, float yVelocity)
            : base(xVelocity, yVelocity)
        {
            this._startXVelocity = xVelocity;
            this._startYVelocity = yVelocity;
        }

        protected override float GetXMovement(int delta)
        {
            if (this._xVelocity >= 0.0f)
            {
                this._xVelocity = this._xVelocity + this._deceleration * delta;
            }

            if (this._xVelocity < 0.0f)
                this._xVelocity = 0.0f;

            Debug.WriteLine("XVel: " + this._xVelocity);

            return this._xVelocity*delta;
        }

        protected override float GetYMovement(int delta)
        {
            if(this._yVelocity >= 0.0f)
            {
                this._yVelocity = this._yVelocity + this._deceleration * delta;
            }

            if (this._yVelocity < 0.0f)
                this._yVelocity = 0.0f;

            Debug.WriteLine("YVel: " + this._yVelocity);

            return this._yVelocity * delta;
        }

        protected override bool GetIsCompleted()
        {
            return this._xVelocity == 0.0f && this._yVelocity == 0.0f;
        }

        protected override void Reset()
        {
            base.Reset();
            this._xVelocity = this._startXVelocity;
            this._yVelocity = this._startYVelocity;
        }
    }
}